﻿using ApiLib.RCL.Utils;
using BootstrapBlazor.Components;

namespace ApiLib.RCL.Models;

/// <summary>
/// 时间范围类型
/// </summary>
public enum DateTimeRangeType
{
    /// <summary>
    /// 空
    /// </summary>
    None,
    /// <summary>
    /// 今天
    /// </summary>
    Today,
    /// <summary>
    /// 一周
    /// </summary>
    Week,
    /// <summary>
    /// 本周
    /// </summary>
    ThisWeek,
    /// <summary>
    /// 一个月
    /// </summary>
    Month,
    /// <summary>
    /// 本月
    /// </summary>
    ThisMonth,
    /// <summary>
    /// 最近3个月
    /// </summary>
    ThreeMonth,
    /// <summary>
    /// 今年
    /// </summary>
    Year
}

/// <summary>
/// 时间范围工具
/// </summary>
public static class DateTimeRangeUtil{
    /// <summary>
    /// 获取时间范围值
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public static DateTimeRangeValue? GetValue(this DateTimeRangeType type)
    {
        return type switch
        {
            DateTimeRangeType.None => null,
            DateTimeRangeType.Today => new DateTimeRangeValue()
            {
                Start = DateTime.Now.DayStart(),
                End = DateTime.Now.DayEnd()
            },
            DateTimeRangeType.Week => new DateTimeRangeValue()
            {
                Start = DateTime.Now.AddDays(-7).DayStart(),
                End = DateTime.Now.DayEnd()
            },
            DateTimeRangeType.ThisWeek => new DateTimeRangeValue()
            {
                Start = DateTime.Now.AddDays(-(int)DateTime.Now.DayOfWeek).DayStart(),
                End = DateTime.Now.DayEnd()
            },
            DateTimeRangeType.Month => new DateTimeRangeValue()
            {
                Start = DateTime.Now.AddDays(-30).DayStart(),
                End = DateTime.Now.DayEnd()
            },
            DateTimeRangeType.ThisMonth => new DateTimeRangeValue()
            {
                Start = DateTime.Now.MonthStart(),
                End = DateTime.Now.DayEnd()
            },
            DateTimeRangeType.ThreeMonth => new DateTimeRangeValue()
            {
                Start = DateTime.Now.AddMonths(-2).MonthStart(),
                End = DateTime.Now.DayEnd()
            },
            DateTimeRangeType.Year => new DateTimeRangeValue()
            {
                Start = DateTime.Now.YearStart(),
                End = DateTime.Now.DayEnd()
            },
            _ => null
        };
    }
}